/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pt.adrz.test;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;
import pt.adrz.uncategorized.SplashInterface;
import pt.adrz.uncategorized.SplashScreen;

/**
 *
 * @author adriano
 */
public class FormSplash extends Form implements CommandListener, SplashInterface {

    private Command exitCMD = new Command("sa1r",Command.EXIT,0);

    private Command cmd1CMD = new Command("cmd1",Command.SCREEN,1);

    private Command cmd2CMD = new Command("cmd2",Command.SCREEN,2);

    private Command backCMD = new Command("back", Command.BACK, 3);

    private TextField timeTF        = new TextField("time: ", null, 2, TextField.NUMERIC);
    private TextField transpTF      = new TextField("transp: ", null, 2, TextField.NUMERIC);
    private TextField delayTimeTF   = new TextField("delayTime: ", null, 2, TextField.NUMERIC);

    SplashScreen sp = new SplashScreen("/Testar/img.png", 0xffffff);


    public FormSplash() {
        super("FormSplash");

        this.addCommand(exitCMD);
        this.addCommand(cmd1CMD);
        this.addCommand(cmd2CMD);
        this.addCommand(backCMD);
        this.append(timeTF);
        this.append(transpTF);
        this.append(delayTimeTF);
        this.setCommandListener(this);
        sp.setInterface(this);
    }





    public void commandAction(Command c, Displayable d) {
       if (c == exitCMD) {
            TestarMIDlet.midlet.destroyApp(true);
        }
        else if (c == cmd1CMD) {
            this.createSplash();
        }
        else if (c == cmd2CMD) {
            TestarMIDlet.midlet.getDP().setCurrent(sp);
            sp.show(); // start
        }
        else if (c == backCMD) {
            TestarMIDlet.midlet.setThisCurrent();
        }
    }




     private void createSplash() {
        try {

            sp.setTime(Integer.parseInt(timeTF.getString()));
            sp.setTransp(Integer.parseInt(transpTF.getString()));
            sp.setDelayImg(Integer.parseInt(delayTimeTF.getString()));
            TestarMIDlet.midlet.getDP().setCurrent(sp);
            sp.show(); // start

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void endTask() {
        TestarMIDlet.midlet.setThisCurrent();
    }


}
